package com.qnw.CardGroupManagement.fragment;
import android.database.sqlite.*;
import android.os.*;
import android.support.v4.app.*;
import android.view.*;
import android.widget.*;
import java.util.*;
import android.view.View.*;
import android.content.*;
import android.widget.AdapterView.*;
import android.database.*;
import android.graphics.*;
import com.qnw.CardGroupManagement.*;
import java.io.*;
import com.qnw.CardGroupManagement.util.*;
import com.qnw.CardGroupManagement.management.*;

import android.util.*;
import com.ygo.feihua.util.*;
import android.graphics.drawable.*;
import com.ygo.feihua.*;
import com.ygo.feihua.adapter.*;
import android.support.v7.widget.*;

public class FragmentDex extends Fragment implements OnClickListener,OnItemSelectedListener
{


	CheckBox c1,c2,c3,c4,c5,c6;

    //列表
	private ListView lv = null;
	private EditText sjk_tm,sjk_km,sjk_name,sjk_xg,sjk_zk,sjk_yk,sjk_atk,sjk_def;
	private SimpleAdapter adapter  = null;
	private Spinner sjk_gs,sjk_sx,sjk_dj,sjk_zz;
	private String gs,dj,sx,zz,xg,km,tm,lx,fl,zd1,zd2,zd3,zd4,name1,atk,def,zk,yk="";
	private ImageView sjk_kt;

	private Button sjk_type_xiaoguo,sjk_type_card,sjk_cardzd,sjk_link,sjk_addts,sjk_delts;
	String sjk_path=null,sjk_lpath=null;

	//记录所有listview的item的数据
	private List<HashMap<String, Object>> mapLists = null;


	SimpleAdapter sa2;
	
	
	HashMap<String,Object>map;
	CheckBox ch;
	ArrayList<HashMap<String,Object>>list2=new ArrayList<HashMap<String,Object>>();
	
	
	HashMap<String,Object>map1;

	private long type_xiaoguo=0;
	private long type_card=0;
	private long card_zd=0;

	
	private String result2="";

	private Gongju gj;
	private DialogUtils du;
	
	private CdbManagement cdbm;
	private String link="";
	
	private String[] card_type,card_type_16
					,card_effect_type,card_effect_type_16
					,card_levels,card_attribute,card_attribute_16
					,card_race,card_race_16
					,card_ot,card_ot_16
	,card_link,card_link_16;

	private LinearLayout kp;

	private String[] lua_toast;

	private String TAG="FragmentDex";
	
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View v=inflater.inflate(R.layout.fragment_dex,null);
		initView(v);
		G5 g5=(G5)getActivity();
		gj=g5.gj;
		du=DialogUtils.getdx(getActivity());
		//	如果是从卡查界面之类的跳转过来的需要传入卡密sjk_km1
		sjk_lpath=SharedPreferenceUtil.getCdbpath();
		sjk_path=SharedPreferenceUtil.getYgopath();
		cdbm=CdbManagement.getdx();
		
		sxCdb(sjk_lpath);
		
		
		card_type=CardMessage.CARD_TYPE;
		card_type_16=CardMessage.CARD_TYPE_16;
		card_effect_type=CardMessage.CARD_EFFECT_TYPE;
		card_effect_type_16=CardMessage.CARD_EFFECT_TYPE_16;
		card_levels=CardMessage.CARD_LEVELS_16;
		card_attribute=CardMessage.CARD_ATTRIBUTE;
		card_attribute_16=CardMessage.CARD_ATTRIBUTE_16;
		card_race=CardMessage.CARD_RACE;
		card_race_16=CardMessage.CARD_RACE_16;
		card_ot=CardMessage.CARD_OT;
		card_ot_16=CardMessage.CARD_OT_16;
		card_link=CardMessage.CARD_LINK;
		card_link_16=CardMessage.CARD_LINK_16;
		
		sjk_addts.setOnClickListener(this);
		sjk_delts.setOnClickListener(this);
		sjk_type_xiaoguo.setOnClickListener(this);
		sjk_type_card.setOnClickListener(this);
		sjk_cardzd.setOnClickListener(this);
		sjk_link.setOnClickListener(this);
		
		zd1="";
		zd2="";
		zd3="";
		zd4="";
		
		sjk_kt.post(new Runnable(){

				@Override
				public void run()
				{
					LayoutParams para;  
					para = sjk_kt.getLayoutParams();  
					para.width=(kp.getHeight()-20)/2*177/254;
					sjk_kt.setLayoutParams(para);

					// TODO: Implement this method
				}
			});

		sxCard(g5.km);
				
		sa2 = new SimpleAdapter(getActivity(), list2, R.layout.item_checkbox,
								new String[]{"text","img","che"},
								new int[]{R.id.ic_text,R.id.ic_check
								});
		//Link值
		for (int i=0;i < card_link.length;i++)
		{
			map1 = new HashMap<String,Object>();
			map1.put("text", card_link[i]);
			map1.put("score", (10 - i) * 10);
			map1.put("che", false);
			list2.add(map1);
		}
		
		
		sjk_kt.setOnClickListener(this);

	
		//设置listview再滚动布局中可滑动
		lv.setOnTouchListener(new OnTouchListener(){ 
				@Override
				public boolean onTouch(View v, MotionEvent event)
				{ 
					// TODO Auto-generated method stub 
					int eventAction = event.getActionMasked(); 
					switch (eventAction)
					{ 
						case MotionEvent.ACTION_DOWN: 
							lv.requestDisallowInterceptTouchEvent(true);
							break;
						case MotionEvent.ACTION_MOVE:
							break;
						case MotionEvent.ACTION_UP: 

							break;
						case MotionEvent.ACTION_CANCEL:
							lv.requestDisallowInterceptTouchEvent(false);
							break; 
						default: 
							break;
					} 
					return false;
				}
			}); 

		lv.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id)
				{
					CheckBox cb = (CheckBox) view.findViewById(R.id.cb_shortcut_check);
					HashMap<String,Object> selectMap = mapLists.get(position);
					boolean checked = (Boolean) selectMap.get("checked");
					if (checked)
					{
						cb.setChecked(false);
						selectMap.put("checked", false);
					}
					else
					{
						cb.setChecked(true);
						selectMap.put("checked", true);
					}

					mapLists.remove(position);
					mapLists.add(position, selectMap);
					//ListView的数据发生变化
					adapter.notifyDataSetChanged();
				}

			});

		sjk_gs.setOnItemSelectedListener(this);
		sjk_sx.setOnItemSelectedListener(this);
		sjk_dj.setOnItemSelectedListener(this);
		sjk_zz.setOnItemSelectedListener(this);
	
		// TODO: Implement this method
		return v;
	}

	public void sxCdb(String path)
	{
		sxCard(null);
		cdbm.setCdb(path);
			// TODO: Implement this method
	}

	private void initView(View v)
	{
		Log.e("初始化控件","初始化控件");
		sjk_gs = (Spinner) v.findViewById(R.id.sjk_gs);
		sjk_dj = (Spinner) v.findViewById(R.id.sjk_dj);
		sjk_sx = (Spinner) v.findViewById(R.id.sjk_sx);
		sjk_zz = (Spinner) v.findViewById(R.id.sjk_zz);
		sjk_tm = (EditText) v.findViewById(R.id.sjk_tm);
		sjk_km = (EditText) v.findViewById(R.id.sjk_km);
		sjk_name = (EditText) v.findViewById(R.id.sjk_name);
		sjk_xg = (EditText) v.findViewById(R.id.sjk_xg);
		sjk_atk = (EditText) v.findViewById(R.id.sjk_atk);
		sjk_def = (EditText) v.findViewById(R.id.sjk_def);
		sjk_zk = (EditText) v.findViewById(R.id.sjk_zk);
		sjk_yk = (EditText) v.findViewById(R.id.sjk_yk);
		sjk_kt = (ImageView) v.findViewById(R.id.sjk_kt);
		sjk_type_xiaoguo=(Button) v.findViewById(R.id.sjk_type_xiaoguo);
		sjk_type_card=(Button) v.findViewById(R.id.sjk_type_card);
		sjk_cardzd=(Button) v.findViewById(R.id.sjk_cardzd);
		sjk_link=(Button) v.findViewById(R.id.sjk_link);
		kp=(LinearLayout) v.findViewById(R.id.kp);
		sjk_addts=(Button) v.findViewById(R.id.sjk_addts);
		sjk_delts=(Button) v.findViewById(R.id.sjk_delts);
		
		mapLists = new ArrayList<HashMap<String, Object>>();
		
		//添加提示文字的布局
		lv = (ListView)v.findViewById(R.id.lv_remain_item);

		adapter = new SimpleAdapter(getActivity(), mapLists,
									R.layout.dialog_item, new String[] { "name", "checked" },
									new int[] { R.id.tv_shortcut_text, R.id.cb_shortcut_check });
		lv.setAdapter(adapter);
		
		// TODO: Implement this method
	}
	
	

	@Override
	public void onItemSelected(AdapterView<?> p1, View p2, int p3, long p4)
	{
		switch(p1.getId()){
			case R.id.sjk_gs:
				gs=p3+1+"";		
				break;
			case R.id.sjk_dj:
				dj=p3+"";
				break;
			case R.id.sjk_sx:
				for (int i=0;i < card_attribute.length;i++)
				{
					if (p3 == i)
					{
						sx = card_attribute_16[i];
					}
				}
				break;
			case R.id.sjk_zz:
				for (int i=0;i < card_race_16.length;i++)
				{
					if (p3 == i)
					{
						zz = card_race_16[i];
					}
				}
				
				break;
		}
		
		// TODO: Implement this method
	}

	@Override
	public void onNothingSelected(AdapterView<?> p1)
	{
		// TODO: Implement this method
	}
	
	
	@Override
	public void onClick(View p1)
	{
		switch(p1.getId()){
			case R.id.sjk_addts:
				sjk_tj();
				break;
			case R.id.sjk_delts:
				sjk_sc();
				break;
			case R.id.sjk_kt:
				startActivityForResult(new Intent(getActivity(),NewWjxz.class).putExtra("lx", NewWjxz.TYPE_PIC),0);
			
				break;		
			case R.id.sjk_cardzd:

				View[] vi=du.dialogzd(true,"卡片字段");
				final EditText sjk_ezd1,sjk_ezd2,sjk_ezd3,sjk_ezd4;
				sjk_ezd1=(EditText) vi[0];
				sjk_ezd2=(EditText) vi[1];
				sjk_ezd3=(EditText) vi[2];
				sjk_ezd4=(EditText) vi[3];
				Button qd=(Button) vi[4];

				sjk_ezd1.setText(zd1);
				sjk_ezd2.setText(zd2);
				sjk_ezd3.setText(zd3);
				sjk_ezd4.setText(zd4);
				
				qd.setOnClickListener(new OnClickListener(){

						@Override
						public void onClick(View p1)
						{
							zd1=sjk_ezd1.getText().toString().trim();
							zd2=sjk_ezd2.getText().toString().trim();
							zd3=sjk_ezd3.getText().toString().trim();
							zd4=sjk_ezd4.getText().toString().trim();
							du.dis();
							// TODO: Implement this method
						}
					});

				if(card_zd!=0){
					//显示一张卡的字段为哪些,每个字段为四位十六进制,总字段组成由各字段拼接而成,不分先后,如永火恶魔字段为永火（45）恶魔（b）,那么他就是45000b或者b0045
					//十进制转换为十六进制
					String zdd=Long.toHexString(card_zd);
					//
					int zds=zdd.length() / 4;

					//Log.e(TAG,"转换前的字段"+card_zd);
					//Log.e(TAG,"转换后的字段"+zdd);
					
					String zdd1="";
					//如果字段个数不是4的整数倍
					if (zdd.length() % 4 != 0)
					{
						//Log.e(TAG,"不是4的整数倍");
						zdd1 = zdd.substring(0, zdd.length() % 4).trim();
						for (int i=0;i < 4 - zdd.length() % 4;i++)
						{
							zdd1 = "0" + zdd1;
						}
						sjk_ezd1.setText(zdd1);

						switch (zds)
						{
							case 1:
								sjk_ezd2.setText(zdd.substring(zdd.length() % 4, zdd.length()));
								break;
							case 2:
								sjk_ezd2.setText(zdd.substring(zdd.length() % 4, zdd.length() % 4+4));
								sjk_ezd3.setText(zdd.substring(zdd.length() % 4 + 4, zdd.length()));
								break;
							case 3:
								sjk_ezd2.setText(zdd.substring(zdd.length() % 4, zdd.length() % 4 + 4));
								sjk_ezd3.setText(zdd.substring(zdd.length() % 4 + 4, zdd.length() % 4 + 4 + 4));
								sjk_ezd4.setText(zdd.substring(zdd.length() % 4 + 4 + 4, zdd.length()));

						}
					}else{
					//	Log.e(TAG,"是4的整数倍");
						switch (zds)
						{
							case 1:
								sjk_ezd1.setText(zdd.substring(0, 4));
								break;
							case 2:
								sjk_ezd1.setText(zdd.substring(0, 4));
								sjk_ezd2.setText(zdd.substring(4, 8));
								break;
							case 3:
								sjk_ezd1.setText(zdd.substring(0, 4));
								sjk_ezd2.setText(zdd.substring(4, 8));
								sjk_ezd3.setText(zdd.substring(8, 12));
								break;
							case 4:
								sjk_ezd1.setText(zdd.substring(0, 4));
								sjk_ezd2.setText(zdd.substring(4, 8));
								sjk_ezd3.setText(zdd.substring(8, 12));
								sjk_ezd4.setText(zdd.substring(12, 16));

						}
					}}

				break;

			case R.id.sjk_link:
				View[] vv3=du.dialoggrid(true,"LINK值",sa2,3);

				final GridView gv3=(GridView) vv3[0];
				Button b3=(Button) vv3[1];

				//显示一张卡的LINK值
				gv3.post(new Runnable() {
						@Override
						public void run()
						{
							
							if (!link.equals(""))
							{
								String link1=Integer.toBinaryString(Integer.parseInt(link));
								int hh=link1.length();	
								if (link1.length() != 9)
								{
									for (int i=0;i < 9 - hh;i++)
									{
										link1 = 0 + link1;
									}
								}
								for (int i=0;i < 9;i++)
								{

									if (link1.substring(i, i + 1).equals("1"))
									{
										if (i!=4)
										{
											int cc=0;
											for(int ii=0;ii<card_link_16.length;ii++){
												if((9-i+"").equals(card_link_16[ii])){
													cc=ii;
													break;
												}
											}
											for(int c=0;c<8;c++){
												CheckBox cb=(CheckBox)gv3.getChildAt(c).findViewById(R.id.ic_check);
												//Log.e("fragmentdex","cb为"+cb.getText());
												if(card_link[cc].equals(((TextView)gv3.getChildAt(c).findViewById(R.id.ic_text)).getText().toString())){
													cb.setChecked(true);
													}
											}
										}
									}

								}
						}}
					});


				b3.setOnClickListener(new OnClickListener(){

						
						@Override
						public void onClick(View p1)
						{
							
							String link1="";
							for (int i=0;i < 9;i++)
							{
								 if(i!=4){
									
									int cc=0;
									for(int ii=0;ii<card_link_16.length;ii++){
										if((9-i+"").equals(card_link_16[ii])){
											cc=ii;
											break;
										}
									}
									for(int c=0;c<8;c++){
										CheckBox cb=(CheckBox)gv3.getChildAt(c).findViewById(R.id.ic_check);
										
										if(card_link[cc].equals(((TextView)gv3.getChildAt(c).findViewById(R.id.ic_text)).getText().toString())){
											if(cb.isChecked()){
												link1+=1;
											}else{
												link1+=0;
											}
										}
									}
								}else{
									link1+=0;
								}
							}					
							if(0==Integer.parseInt(link1,2)){
								link="";
								sjk_def.setEnabled(true);
								sjk_dj.setEnabled(true);
								sjk_def.setText("0");
								sjk_dj.setSelection(0);
							}else{
								link=Integer.parseInt(link1,2)+"";
								sjk_def.setText(link);
								sjk_def.setEnabled(false);
								sjk_dj.setEnabled(false);
								String s=link1;
								int n=s.length()-s.replaceAll("1", "").length();
								sjk_dj.setSelection(n);
							}
							du.dis();
							// TODO: Implement this method
						}
					});

				
				
				break;
			case R.id.sjk_type_card:
				final CheckboxAdapter cardAdapter=new CheckboxAdapter(getActivity(),card_type,card_type_16,type_card);
				View[] vv1=du.dialogRec(true,"卡片类型",cardAdapter,new GridLayoutManager(getActivity(),3));
				Button b2=(Button) vv1[1];
				b2.setOnClickListener(new OnClickListener(){

						@Override
						public void onClick(View p1)
						{
							int result1=0;
							for (int i=0;i <cardAdapter.getItemCount();i++)
							{
								if (cardAdapter.getop(i).isChecked())
								{
									result1 += Integer.valueOf(card_type_16[i], 16);
								}					
							}
							type_card=result1;
							du.dis();
							// TODO: Implement this method
						}
					});

				break;
			case R.id.sjk_type_xiaoguo:

				final CheckboxAdapter effectAdapter=new CheckboxAdapter(getActivity(),card_effect_type,card_effect_type_16,type_xiaoguo);
				View[] vv2=du.dialogRec(true,"卡片类型",effectAdapter,new GridLayoutManager(getActivity(),3));
				Button bb2=(Button) vv2[1];
				bb2.setOnClickListener(new OnClickListener(){

						@Override
						public void onClick(View p1)
						{
							int result1=0;
							for (int i=0;i <effectAdapter.getItemCount();i++)
							{
								if (effectAdapter.getop(i).isChecked())
								{
									result1 += Integer.valueOf(card_effect_type_16[i], 16);
								}
							}
							type_xiaoguo=result1;
							du.dis();
							// TODO: Implement this method
						}
					});
				break;
		}
		// TODO: Implement this method
	}
	
	public void sxCard(String km){
		if (km != null)
		{
			this.km=km;
			sjk_km.setText(km);
			zd1="";
			zd2="";
			zd3="";
			zd4="";
			final Cursor datas=cdbm.getCdb().query("datas", new String[]{"id","ot","type","level","attribute","race","atk","def","alias","category","setcode"}, "id LIKE?", new String[]{"%" + km}, null, null, null);
			Cursor texts=cdbm.getCdb().query("texts", new String[]{"id","name","desc","str1","str2","str3","str4","str5","str6","str7","str8","str9","str10","str11","str12","str13","str14","str15","str16"}, "id LIKE?", new String[]{"%" + km}, null, null, null);
			if (datas.getCount() != 0 && texts.getCount() != 0)
			{//获取集合的个数，如果不为0(没查到则为0)
				datas.moveToNext();//移动到第一行，默认是0，没有写这句，直接获取值会抛异常
				texts.moveToNext();
			
				
				type_card=Integer.parseInt(datas.getString(2).trim());
				type_xiaoguo=Long.parseLong(datas.getString(9).trim());
				def=datas.getString(7).trim();
				
				for (int i=0;i < card_ot_16.length;i++)
				{
					if (card_ot_16[i].equals(datas.getString(1).trim()))
					{
						sjk_gs.setSelection(i);
					}
				}
				
				String lzk = "0",lyk = "0";
				if ((type_card & Integer.valueOf("4000000", 16))!=0)
				{
					link=def;
					sjk_def.setEnabled(false);
				sjk_dj.setEnabled(false);
						String s=Integer.toBinaryString(Integer.parseInt(def));

						int n=s.length()-s.replaceAll("1", "").length();
					sjk_dj.setSelection(n);
				}else{
					link="";
					
					sjk_def.setEnabled(true);
					
					sjk_dj.setEnabled(true);
					//等级存在数据库中的为10进制数,&0xff得到等级,右移24位再&0xff得到左刻度,右移16位再&0xff得到右刻度
					//等级计算公式：(等级&0xff)+((左刻度&0xff)<<16)+((右刻度&0xff)<<24)
					String dj4;//=Integer.toHexString(Integer.parseInt(datas.getString(3).trim()));
					long level=Integer.parseInt(datas.getString(3).trim());
					//左刻度
					lzk=CardUtil.getLeftScale(level);
					//右刻度
					lyk=CardUtil.getRightScale(level);
					//等级
					dj4=CardUtil.getLevel(level);
					
					
				//设置等级spinner默认选项

				for (int i=0;i < card_levels.length;i++)
				{
					if (Integer.parseInt(dj4)==Integer.parseInt(card_levels[i]))
					{
						sjk_dj.setSelection(i);
					}

				}

				}
				
				//设置属性spinner默认选项
				String sx2=Integer.toHexString(Integer.parseInt(datas.getString(4).trim()));
				for (int i=0;i < card_attribute_16.length;i++)
				{
					if (sx2.equals(card_attribute_16[i]))
					{
						sjk_sx.setSelection(i);
					}
				}

				
				//设置种族spinner默认选择
				String zz1=Integer.toHexString(Integer.parseInt(datas.getString(5).trim()));
				for (int i=0;i < card_race_16.length;i++)
				{
					if (zz1.equals(card_race_16[i]))
					{
						sjk_zz.setSelection(i);
					}
				}
				
				
				card_zd=Long.parseLong(datas.getString(10));
				sjk_atk.setText(datas.getString(6));
				sjk_tm.setText(datas.getString(8));
				sjk_name.setText(texts.getString(1));
				sjk_xg.setText(texts.getString(2));
				sjk_zk.setText(lzk);
				sjk_yk.setText(lyk);
				sjk_def.setText(def);
				mapLists.clear();
				
				//显示一张卡的提示文字为哪些
				for (int i=3;i < 19;i++)
				{

					if (texts.getString(i)!=null&&!texts.getString(i).equals("")){
						HashMap<String,Object> addMap = new HashMap<String,Object>();
						addMap.put("name", texts.getString(i));
						addMap.put("checked", false);
						mapLists.add(addMap);
					}
				}
				adapter.notifyDataSetChanged();
			}
			//显示卡图
		/*	Bitmap bm=gj.getkt(km);
			sjk_kt.setImageBitmap(bm);*/
			
			Gongju.setKt(getActivity(),sjk_kt,km);
		}else{
			mapLists.clear();
			adapter.notifyDataSetChanged();
			sjk_km.setText("");
			sjk_gs.setSelection(0);
			sjk_dj.setSelection(0);
			sjk_sx.setSelection(0);
			sjk_zz.setSelection(0);
			sjk_atk.setText("0");
			sjk_def.setText("0");
			sjk_tm.setText("");
			sjk_name.setText("");
			sjk_xg.setText("");
			sjk_zk.setText("0");
			sjk_yk.setText("0");
			mapLists.clear();
			sjk_def.setEnabled(true);
			sjk_kt.setImageResource(R.drawable.unknown);
			adapter.notifyDataSetChanged();
			sjk_dj.setEnabled(true);
			
		}
	}
	
	public void save(){	
	
		gj.closeKeyboard();
		if (cdbm.getCdb() == null){
			gj.show("未选择数据库");
		}else{
			getMessage();
			if(km.equals("")||name1.equals("")){
				gj.show("信息未填完整");
			}else{
			String zd=getZd();
			String level=getLevel();
			
				Cursor sdatas=cdbm.getCdb().query("datas", new String[]{"id"}, "id LIKE?", new String[]{"%" + km}, null, null, null);
				ContentValues c=new ContentValues();//用来包装数
				c.put("id", km);
				c.put("race", Integer.valueOf(zz, 16).toString());//将要插入的值
				c.put("attribute", Integer.valueOf(sx, 16).toString());
				c.put("level",level);
				c.put("type", lx);
				c.put("atk", atk);
				c.put("def", def);
				c.put("ot", gs);
				c.put("category", fl);
				c.put("setcode", Integer.valueOf(zd, 16).toString());
				if (tm.equals("")){
					c.put("alias", "" + 0);
				}else{
					c.put("alias", tm);
				}	
				ContentValues c1=new ContentValues();
				c1.put("id", km);
				c1.put("name", name1);
				c1.put("desc", xg);
				for (int i=0;i < 16;i++)
				{
					if(i<lua_toast.length){
						c1.put("str" + Integer.toString(i + 1), lua_toast[i]);
					}else{
						c1.put("str" + Integer.toString(i + 1), "");
					}
				}
				
				if(sdatas.getCount()==0){
					cdbm.getCdb().insert("datas",null,c);
					cdbm.getCdb().insert("texts", null, c1);
					gj.show("添加成功");
				}else{
					cdbm.getCdb().update("datas", c, "id=?", new String[]{km});
					cdbm.getCdb().update("texts", c1, "id=?", new String[]{km});
					gj.show("修改成功");
				}	
				
				copyKt();
			}	
		}
	}

	private void copyKt()
	{
		
			if (result2 != null && !result2.equals(""))
			{
				try {
					final String path=SharedPreferenceUtil.getYgopath() + "/pics/" + sjk_km.getText().toString() .trim() + ".jpg";
					FileUtil.copyFile(result2, path , true);
				} catch (IOException e) {
					gj.show("保存卡图失败,原因为" + e);
				}
			}
	}

	
	private void getMessage(){
		tm = sjk_tm.getText().toString().trim();
		km = sjk_km.getText().toString().trim();
		xg = sjk_xg.getText().toString().trim();
		name1 = sjk_name.getText().toString().trim();
		atk = sjk_atk.getText().toString().trim();
		zk = sjk_zk.getText().toString().trim();
		yk = sjk_yk.getText().toString().trim();

		if (atk.equals("")){
			atk = "" + 0;
		}

		if (link.equals("")){
			def = sjk_def.getText().toString().trim();
			if (def.equals("")){
				def = "" + 0;
			}
		}else{
			def = link;
		}

		lua_toast=new String[mapLists.size()];
		for (int i=0;i < mapLists.size();i++){
			//String oo=	mapLists.get(i).toString();
			lua_toast[i]=(String) mapLists.get(i).get("name");//=	oo.substring(oo.indexOf("name=") + 5, oo.length() - 1).trim();
		}

		
		
		fl = type_xiaoguo + "";
		lx = type_card + "";
		
	}
	
	private String getZd(){
		
		String zd="";	
		if (!zd1.equals("")){
			int ii=zd1.length();
			for (int i=0;i < 4 - ii;i++){
				zd1 = "0" + zd1;
			}
			zd = zd1;
		}
		
		if (!zd2.equals("")){
			int ii=zd2.length();
			for (int i=0;i < 4 - ii;i++){
				zd2 = "0" + zd2;
			}
			zd= zd+ zd2;
		}
		
		if (!zd3.equals("")){
			int ii=zd3.length();
			for (int i=0;i < 4 - ii;i++){
				zd3 = "0" + zd3;
			}
			zd = zd + zd3;
		}
		
		if (!zd4.equals("")){
			int ii=zd4.length();
			for (int i=0;i < 4 - ii;i++){
				zd4 = "0" + zd4;
			}
			zd = zd + zd4;
		}
		if(zd.trim().equals("")){
			zd="0";
		}
		return zd;
	}
	
	private String getLevel(){
		
		if ((type_card & Integer.valueOf("4000000", 16)) != 0)
		{
			String s=Integer.toBinaryString(Integer.parseInt(def));
			int n=s.length() - s.replaceAll("1", "").length();
			return n + "";
		}else{
			if(zk.equals("")||yk.equals("")){
				zk=0+"";
				yk=0+"";
			}
			return  CardUtil.getLevel(Integer.parseInt(dj), Integer.parseInt(zk), Integer.parseInt(yk));
		}	
	}
	

	public void sjk_tj()
	{
		View[] vv=du.dialoge(false,"","请输入脚本提示文字");
		final EditText ed=(EditText) vv[0];
		Button bt=(Button) vv[1];
		bt.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					String text = ed.getText().toString().trim();
					if (text.equals(""))
					{
						gj.show( "请输入提示文字");
					}else{
						du.dis();
						HashMap<String,Object> addMap = new HashMap<String,Object>();
						addMap.put("name", text);
						addMap.put("checked", false);
						mapLists.add(addMap);
						adapter.notifyDataSetChanged();
					}
					// TODO: Implement this method
				}
			});
		
	}


	public void sjk_sc()
	{
		List<HashMap<String,Object>> deleteMap = new ArrayList<HashMap<String,Object>>();
		for (HashMap<String,Object> map:mapLists)
		{
			if ((Boolean)map.get("checked"))
			{
				deleteMap.add(map);
			}
		} 
		if(deleteMap.size()==0){
			gj.show("请选择要删除的提示文字");
		}else{
		//移除所有被选中的item
		mapLists.removeAll(deleteMap);
		adapter.notifyDataSetChanged();

		}

	}

	public void setkt(String path){	
		result2 = path;
		Bitmap bm=BitmapFactory.decodeFile(result2);
		sjk_kt.setImageBitmap(bm);
	}
}
